package com.hmall.user.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hmall.user.pojo.Address;
import com.hmall.user.service.IAddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/address")
public class AddressController {
    @Autowired
    private IAddressService addressService;

    @GetMapping("/uid/{id}")
    public List<Address> getAddressByUid(@PathVariable Long id) {
        QueryWrapper<Address> queryWrapper = new QueryWrapper<Address>().eq("user_id", id);
        return addressService.list(queryWrapper);
    }

    @GetMapping("/{id}")
    public Address getAddressById(@PathVariable Long id) {
        return addressService.getById(id);
    }
}
